#!/usr/bin/env python 
# -*- coding: utf-8 -*-
# @Time    : 2023/4/12 21:58
# @Author  : WJQ
# @Site    : 
# @File    : Edge.py
# @Software: PyCharm
from typing import Optional

from models.Node import Node, Component


class CrawlEdge:
    method: str
    element: Component

    def __init__(self, method, element: Component):
        self.method = method
        if element == None:
            self.element = Component({'tagName': '', 'className': '', 'rect': {'x': 0, 'y': 0, 'width': 0, 'height': 0}, 'text': ''})
        self.element = element

    def __eq__(self, other):
        return self.method == other.method and self.element == other.element

    def __repr__(self):
        return f"method: {self.method}, element: {self.element}"

class Edge:
    n1: Node
    n2: Node
    value: Optional[CrawlEdge]
    parent: 'Edge'
    visited: bool

    def __init__(self, n1, n2, value, parent=None):
        self.n1 = n1
        self.n2 = n2
        self.value = value
        self.visited = False
        self.parent = parent

    def __eq__(self, other):
        return self.n1 == other.n1 and self.n2 == other.n2 and self.value == other.value

    def __hash__(self):
        return hash(hash(self.n1) + hash(self.n2) + hash(self.value))

    def __repr__(self):
        return str(self.n1) + " -(" + str(self.value) + ")-> " + str(self.n2)